/*
 * I've commented out this part as it otherwise collides with circledetect during compilation
 * //Mårten
 *
 */
/*
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <time.h>
#include <string.h>

#define PORT 4444
//#define SRV_IP "192.168.0.7"
#define SRV_IP "127.0.0.1"

struct datagram data;
struct sockaddr_in si_other;

int s, i, slen=sizeof(si_other);


void diep(char *s){
	perror(s);
	exit(1);
} 


struct datagram{
	char header[4];	// Header to check that it is a packet we want to use
	int16_t offset;		
	uint16_t angle;
	uint16_t pos;
};

void init_socket(){

	data.header[0] = 'd';
	data.header[1] = 'a';
	data.header[2] = 't';
	data.header[3] = 'a';

	data.offset = 4;
	data.angle = 36;
	data.pos = 100;

	if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
		diep("socket");

	memset((char *) &si_other, 0, sizeof(si_other));
	si_other.sin_family = AF_INET;
	si_other.sin_port = htons(PORT);
	if (inet_aton(SRV_IP, &si_other.sin_addr)==0) {
		fprintf(stderr, "inet_aton() failed\n");
		exit(1);
	}


}

void send_datagram(struct datagram data){
	if (sendto(s, &data, sizeof(data), 0, &si_other, slen)==-1)
		diep("sendto()");


}

void do_it_now(int angle){
	init_socket();
	data.angle=angle;
}


int main(void){
	init_socket();
	sleep(1);

	printf("Sending packets\n");
	int i = 0;
	while(i < 4){
		send_datagram(data);

		data.angle +=10;
		printf("%i Angle: %i, pos: %i\n", i, data.angle, data.pos);
		i++;
		usleep(3000000);
	}
	printf("Server done\n");
	close(s);
	return 0;
}

*/
